package com.gupaoedu.vip.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by zhaozhonghai on 2017/5/22.
 */
public class LianJia implements InvocationHandler {
    private Person target;
    public Object getInstance(Person target){
        this.target=target;
        Class clazz=target.getClass();
        return Proxy.newProxyInstance(clazz.getClassLoader(),clazz.getInterfaces(),this);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("用户的名字"+this.target.getName());
        System.out.println("用户的要求"+this.target.getSize()+this.target.getPrice());
        System.out.println("开始帮用户找房子,找到房子，联系客户看房子");
        System.out.println("----------------------");
        method.invoke(this.target,args);
        System.out.println("----------------------");
        System.out.println("客户满意，收佣金，结束");
        return null;
    }
}
